#include "token.h"

int getToken(char* uid,char* token){
    char key[66] = "e4rTcV5yU1iR2pOaZxEr7HtYv4BnMlKjIuP9oFg3dSqWe8rTcV5yU1iR2pOaZxort";
   // 因为要保证token固定，故不加入时间信息
   // char iat[26] = {0};
   // time_t t = time(NULL);
   // ctime_r(&t,iat);
   // printf("current time = %s\n",iat);
    char buf[1024] = {0};
    sprintf(buf,"%s.%s",uid,key);
    unsigned char md[32] = {0};
    SHA256((unsigned char*)buf,strlen(buf),md);
    for(int i = 0;i < 32;i++){
        char temp[3] = {0};
        sprintf(temp,"%02x",md[i]);
        strcat(token,temp);
    }
    return 0;
}

int cmpToken(char* uid,char* token){
    char curToken[65] = {0};
    getToken(uid,curToken);
    if(strcmp(token,curToken) == 0){
        return 0;
    }
    return -1;
}
